(function () {
    var serverData = {};
    serverData.key='';
    serverData.startTime='';
    serverData.endTime='';
    var serverTable;
    jQuery(document).ready(function () {
        serverTable = jQuery('#logTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/log/getpage',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [
                {
                data: null
                },
                {
                    data: 'user.name'
                },
                {
                    data: 'logDevice'
                },
                {
                    data: 'operateType'
                },
                {
                    data: 'createTime',
                    render: function (data, type, full, meta) {
                            if (data)
                                return moment(data).format('YYYY/MM/DD HH:mm:ss');
                            else
                                return '';
                     }
                },
                {
                    data: 'content'
                }  
              ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                } 
            }
        });
    });
    ///查询
    jQuery('.searchBtn').on('click',function(){
		var startDate=jQuery('.startDate').val();
		var startTime=jQuery('.starTime').val();
		if(startDate!=="" && startTime==""){
			startTime="00:00";
		}
		var start=startDate+" "+startTime;
		var endDate=jQuery('.endDate').val();
		var endTime=jQuery('.endTime').val();
		if(endDate!=="" && endTime=='' ){
			endTime="23:59";
		}
		var end=endDate+" "+endTime;
		var key=jQuery('#keyword').val();
		serverData.key=key;
		serverData.startTime=start;
		serverData.endTime=end;
		serverTable.draw();				
	});
	//重置
	jQuery('.resetBtn').on('click',function(){
		jQuery('#keyword').val('');
		jQuery('.startDate').val('');
		jQuery('.starTime').val('');
		jQuery('.endDate').val('');
		jQuery('.endTime').val('');
		serverData.key='';
		serverData.startTime='';
		serverData.endTime='';
		serverTable.draw();		
	})
})();